<?php
/**
 * Created by PhpStorm.
 * User: liu85
 * Date: 2018/7/12
 * Time: 21:14
 */

namespace app\admin\controller;


use app\admin\business\AdminBusiness;
use app\common\helper\AdminInfoHelper;
use think\App;
use think\facade\View;

class Login extends Base
{
    private $adminBusiness;

    public function __construct(AdminInfoHelper $adminInfoHelper, App $app = null)
    {
        parent::__construct($app);
        $this->adminBusiness = new AdminBusiness($adminInfoHelper);

    }

    public function login()
    {
        return View::fetch();
    }

    /**
     * 登录
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function doLogin()
    {
        $userName = $this->request->param('username');
        $pass = $this->request->param('password');
        $this->adminBusiness->doLogin($userName, $pass);
    }

    public function index()
    {
        if(session('aid')){
            $this->redirect('/admin/index');
            exit;
        }
        return view('login');
    }

    /**
     * 退出登录
     */
    public function logout()
    {
        session(null);
        session_destroy();
        unset($_SESSION);
        $this->redirect('/admin/login');
    }
}